#!/bin/bash
#------------------------------------------
# desc:
#     字符串函数扩展
# author:
#     dockerlin@163.com
# ------------------------------------------

cxlib_string(){
    logger_debug "checking cxlib_string support!"
    # 返回0表示环境支持
    return 0
}

# ----------------------------
# 返回大写
# 例如：UPPERCASE=$(echo $VARIABLE | tr '[a-z]' '[A-Z]')   (把VARIABLE的小写转换成大写)
#       LOWERCASE=$(echo $VARIABLE | tr '[A-Z]' '[a-z]')   (把VARIABLE的大写转换成小写)
# usage: upcase=`cxlib_toupper "cxl char 123"`
# ----------------------------
cxlib_toupper(){
    echo -n "$1" | tr '[a-z]' '[A-Z]' && return 0 || return 1
}

# ----------------------------
# 返回小写
# 例如：UPPERCASE=$(echo $VARIABLE | tr '[a-z]' '[A-Z]')   (把VARIABLE的小写转换成大写)
#       LOWERCASE=$(echo $VARIABLE | tr '[A-Z]' '[a-z]')   (把VARIABLE的大写转换成小写)
# usage: lowcase=`cxlib_tolow "CXL CHAR 123"`
# ----------------------------
cxlib_tolow(){
    echo -n "$1" | tr '[A-Z]' '[a-z]' && return 0 || return 1
}

# ----------------------------
# 在数组或字符串中寻找另一个字符串
# usage: cxlib_indexOf "ccc" "CXL CHAR 123"
# ----------------------------
cxlib_indexOf(){
    if [ -z "$1" ] ; then return 1; fi
    if [ -z "$2" ] ; then return 2; fi
    for x in $2
    do
	    if [ $x = $1 ] ; then return 0; fi
    done
    return 3
}